import { batchMinMaxNormalize } from '../utils/common';
import HotEventEntity from '../entity/HotEventEntity';
import http from '../utils/http';
import { AmountData } from '../stores/GraphDataStore';

export interface SelectionType {
  label: string;
  value: string;
}

export interface DateRange {
  startDate: string;
  endDate: string;
}

export default class GraphDataApi {

  async getDateRangeData(): Promise<DateRange> {
    return await http.get('/amountStatistics/dateRange');
  }

  async getCaseAmountGraphData(startDate: string, endDate: string): Promise<AmountData[]> {
    return await http.get('/amountStatistics/districts');
  }

  async getCaseCategoryGraphData(startDate: string, endDate: string): Promise<AmountData[]> {
    return await http.get('/amountStatistics/caseCategories');
  }

  async getCaseTypeGraphData(startDate: string, endDate: string): Promise<AmountData[]> {
    return await http.get('/amountStatistics/caseTypes');
  }

  async getCaseHandlingGraphData() {
    return await http.get('');
  }
  async getCaseTrendGraphData(startDate: string, endDate: string): Promise<AmountData[]> {
    return await http.get('/amountStatistics');
  }

  async getHotWordsData() {
    const { hotWords } = await http.get('/hotWords');
    const nameList = Object.keys(hotWords);
    // 归一化处理
    const valueList = batchMinMaxNormalize(nameList.map(name => hotWords[name]), 10, 100);
    return nameList.map((name, i) => ({
      name,
      value: valueList[i]
    }));
  }

  async getHotEventsData() {
    const hotEvents: HotEventEntity[] = await http.get('/hotEvents');
    const hotEventsGroup: {} = {};
    hotEvents.forEach((hotEvent: HotEventEntity) => {
      hotEvent = new HotEventEntity(hotEvent);
      return hotEventsGroup[hotEvent.category]
        ? hotEventsGroup[hotEvent.category].push(hotEvent) : hotEventsGroup[hotEvent.category] = [hotEvent];
    });
    return Object.keys(hotEventsGroup).map(key => ({
      tag: key,
      hotEvents: hotEventsGroup[key]
    }));
  }

  // 拉取工单办结情况数据
  getCompletedData(): Array<AmountData> {
    let result = require('../assets/json/completedData.json');
    return result;
  }
  // 完成工单统计
  getCompletedAnalysis(): Array<AmountData> {
    let result = require('../assets/json/completedAnalysis.json');
    return result;
  }
  // 拉取工单受理情况数据
  getAcceptedData(): Array<AmountData> {
    let result = require('../assets/json/acceptedData.json');
    return result;
  }
  // 受理工单统计
  getAcceptedAnalysis(): Array<AmountData> {
    let result = require('../assets/json/acceptedAnalysis.json');
    return result;
  }
  // 拉取热门诉求数据
  getHotRequestData(): Array<AmountData> {
    let result = require('../assets/json/hotRequestData.json');
    return result;
  }
  // 拉取承办单位热门诉求
  getOrgHotRequestData(): Array<AmountData> {
    let result = require('../assets/json/orgHotRequestData.json');
    return result;
  }

  // 拉取热词数据
  getHotWordData(): Array<AmountData> {
    let result = require('../assets/json/hotwordData.json');
    return result;
  }

  // 拉取图表选项
  getGraphSelection(): Array<Array<SelectionType>> {
    let result = require('../assets/json/graphSelectionData.json');
    return result;
  }

  // 获取热词列表
  getHotwordData(): Array<AmountData> {
    let result = require('../assets/json/hotwordData.json');
    return result;
  }

  // 获取行政区受理数据
  getDistrictAcceptedData(): Array<AmountData> {
    let result = require('../assets/json/districtAcceptedData.json');
    return result;
  }
  // 承办单位工单受理量top10
  getOrgAcceptedTopTenData(): Array<AmountData> {
    let result = require('../assets/json/orgAcceptedTopTenData.json');
    return result;
  }
  // 热点诉求统计top10
  getRequestTopTenData(): Array<AmountData> {
    let result = require('../assets/json/requestTopTenData.json');
    return result;
  }
  // 诉求种类
  getRequestTypeData(): Array<AmountData> {
    let result = require('../assets/json/requestTypeData.json');
    return result;
  }
  // 诉求种类合计
  getRequestTypeTableSource(): Array<AmountData> {
    let result = require('../assets/json/requestTableSource.json');
    return result;
  }
}